package com.jp.knowledge.my.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.my.adapter.OptionAdapter;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.resources.OrganizeJoinRes;
import com.jp.knowledge.view.RecycleViewDiver;

import org.xutils.view.annotation.ViewInject;

public abstract class OptionActivity extends SlidingActivity implements RecycleVAdapter.OnItemClickListener {

    @ViewInject(R.id.department_show_rv)
    private RecyclerView searchList;

    protected OptionAdapter adapter;

    @Override
    protected int getResourceId() {
        return R.layout.activity_department;
    }

    @Override
    protected void init() {
        initTitle(getIntent().getStringExtra(OrganizeJoinRes.TITLE));
        findViewById(R.id.department_btn_create).setVisibility(View.GONE);

        adapter = new OptionAdapter(this, new String[]{});
        adapter.addItemClickListener(this);
        searchList.setHasFixedSize(true);
        searchList.setLayoutManager(new LinearLayoutManager(this));
        searchList.addItemDecoration(new RecycleViewDiver(this, LinearLayout.HORIZONTAL));
        searchList.setAdapter(adapter);
        leftIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initTitle(String title) {
        topName.setText(title);
        topDesc.setVisibility(View.GONE);
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        rightIcon.setVisibility(View.GONE);
    }

    @Override
    public void itemSelect(int position) {
        Intent intent = getIntent();
        intent.putExtra(OrganizeJoinRes.RESPONSE_RESULT, adapter.getData(position));
        intent = putMessageToIntent(intent, position);
        setResult(RESULT_OK, intent);
        finish();
    }

    public abstract Intent putMessageToIntent(Intent intent, int positoin);
}
